<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
const onClickLeft = () => {
  // TODO 点击左侧返回按钮
  if(props.back){
    return props.back()
  }
//   判断是否有历史记录
    if (history.state.back ) {
        // 1.存在回跳地址就返回
        router.back()
    } else {
        // 2.不存在跳到首页
        router.push('/')
    }
}

// 1. 接收父组件传递的props
const props = defineProps<{
  title?: string
  rightText?: string
  leftText?: string
  fixed?: boolean
  back?:()=>void
  placeholder?:boolean
}>()
// 2. 子传父
const emit = defineEmits<{
  (e: 'click-right'): void
}>()

</script>

<template>
  <van-nav-bar
    :fixed="fixed"
    left-arrow
    :title="title"
    :right-text="rightText"
    :left-text="leftText"
    @click-left="onClickLeft"
    @click-right="emit('click-right')"
    :placeholder="placeholder"
  >
  
  </van-nav-bar>
</template>

<style lang="scss" scoped>
// vue3的样式穿透
// ::v-deep函数代替deep
:deep() {
  .van-nav-bar {
    &__arrow {
      font-size: 18px;
      color: var(--cp-text1);
    }
    &__text {
      font-size: 15px;
      color:black
    }
  }
}
</style>
